home *** CD-ROM | disk | FTP | other *** search
/ Sprite 1984 - 1993 / Sprite 1984 - 1993.iso / src / lib / c / ulog / Ulog_LastLogin.c < prev    next >
Encoding:
C/C++ Source or Header  |  1988-09-23  |  2.1 KB  |  86 lines

  1. /* 
  2.  * Ulog_LastLogin.c --
  3.  *
  4.  *    Source code for the Ulog_LastLogin procedure.
  5.  *
  6.  * Copyright 1988 Regents of the University of California
  7.  * Permission to use, copy, modify, and distribute this
  8.  * software and its documentation for any purpose and without
  9.  * fee is hereby granted, provided that the above copyright
  10.  * notice appear in all copies.  The University of California
  11.  * makes no representations about the suitability of this
  12.  * software for any purpose.  It is provided "as is" without
  13.  * express or implied warranty.
  14.  */
  15.  
  16. #ifndef lint
  17. static char rcsid[] = "$Header: Ulog_LastLogin.c,v 1.4 88/09/22 22:14:13 douglis Exp $ SPRITE (Berkeley)";
  18. #endif not lint
  19.  
  20.  
  21. #include <ulog.h>
  22. #include "ulogInt.h"
  23.  
  24.  
  25. /*
  26.  *----------------------------------------------------------------------
  27.  *
  28.  * Ulog_LastLogin --
  29.  *
  30.  *    Retrieve information for the last login of the specified user.
  31.  *
  32.  * Results:
  33.  *    The user log data structure is returned if the retrieval is
  34.  *    successful.  If there is no valid entry for the specified user,
  35.  *    or if an error occurs accessing the 'last log', NULL is returned.
  36.  *
  37.  * Side effects:
  38.  *    The 'last log' is opened, locked, and read before closing it again.
  39.  *
  40.  *----------------------------------------------------------------------
  41.  */
  42.  
  43.  
  44. Ulog_Data *
  45. Ulog_LastLogin(uid)
  46.     int uid;
  47. {
  48.     static Ulog_Data data;
  49.     char buffer[ULOG_RECORD_LENGTH];
  50.     int status;
  51.     int count;
  52.     
  53.     status = Db_ReadEntry(LASTLOG_FILE_NAME, buffer, uid, ULOG_RECORD_LENGTH,
  54.                DB_LOCK_BREAK);
  55.     if (status != 0) {
  56.     return((Ulog_Data *) NULL);
  57.     }
  58.     if (buffer[0] == '\0') {
  59.     errno = EACCES;
  60.     return((Ulog_Data *) NULL);
  61.     }
  62.     /*
  63.      * Try to parse the record.  It's okay if the location field
  64.      * doesn't match because it may be empty.
  65.      */
  66.     count = sscanf(buffer, ULOG_FORMAT_STRING, &data.uid,
  67.            &data.hostID, &data.portID,
  68.            &data.updated, data.location);
  69.     if (count < ULOG_ITEM_COUNT - 1) {
  70.     syslog(LOG_ERR, "Ulog_LastLogin: unable to parse record %d",
  71.            uid);
  72.     errno = EACCES;
  73.     return((Ulog_Data *) NULL);
  74.     } else if (count == ULOG_ITEM_COUNT - 1) {
  75.     data.location[0] = '\0';
  76.     }
  77.     return(&data);
  78. }
  79.  
  80.  
  81.  
  82.  
  83.  
  84.  
  85.  
  86.